<template>
  <div class="content">
    <!--分类-->
    <div class="edu-filter-box">
      <div class="category2-box">
        <div data-v-5b181bf1="" class="box">
          <div class="first-item">分类：</div>
          <div class="item-box">
            <div :class="['item',{'active':!categoryId}]" @click="changeCategoryId('')"> 全部</div>
            <div :class="['item',{'active':categoryId===item.id}]"  v-for="(item,index) in categoryList" :key="index" @click="changeCategoryId(item.id)"> {{item.name}}</div>
          </div>
        </div>
      </div>
    </div>

    <!--  内容-->
    <div class="contanier">
      <div class="left-contanier">

        <div class="topic-item" v-for="(item,index) in articleList" :key="index" @click="goInfo(item.id)">
          <div class="topic-item-comp">
            <div class="topic-thumb"><img :src="item.coverImage" alt="item.title">
            </div>
            <div class="topic-body">
              <div class="topic-title">{{item.title}}</div>
              <div class="topic-info">
                <div class="category">{{item.categoryName}}</div>
                <span class="read-count">{{item.viewCount}}次阅读</span></div>
            </div>
          </div>
        </div>

      </div>

      <div class="right-contanier">
        <div class="right-list">
          <div class="tit">
            热门文章
          </div>
          <div class="right-box">
            <div class="topic-item" v-for="(item,index) in hotArticle" :key="'h-'+index" @click="goInfo(item.id)">
              <div class="topic-item-comp">
                <div class="topic-thumb"><img :src="item.coverImage" alt="item.title">
                </div>
                <div class="topic-body">
                  <div class="topic-title">{{item.title}}</div>
                  <div class="topic-info">
                    <div class="category">{{item.categoryName}}</div>
                    <span class="read-count">{{item.viewCount}}次阅读</span></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="paging">
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        background
        style="padding: 30px 0; text-align: center;"
        @current-change="getData"
        layout="prev, pager, next">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import articleApi from "../../api/article";

  export default {
    data() {
      return {
        page:1,
        limit:4,
        articleList: [],
        total:0,
        categoryId:'',
        categoryList:[],
        hotArticle:[]
      }
    },
    mounted() {
      this.getData()
    }
    , methods: {
      getData(page = 1) {
        this.page = page;
        console.log("gggg:"+this.categoryId)
        articleApi.getPageList(this.page, this.limit,this.categoryId)
          .then(response => {
          this.articleList = response.data.data.list
          this.total = response.data.data.totalCount
          this.categoryList=response.data.data.categoryList
            // console.log("fffff:"+response.data.data.list)
          //根据浏览量获取热门文章
          if(!this.categoryId&&this.page==1){
            this.hotArticle=response.data.data.list.sort((a,b)=>{
              return b.viewCount-a.viewCount
            }).slice(0,2)
          }
        })
      },
      //修改分类
      changeCategoryId(id){
        console.log("fff:"+id)
        this.categoryId=id
        this.getData()
      },
      goInfo(id){
        this.$router.replace('/article/'+id)
      }
    }
  }
</script>
<style scoped>
  .contanier, .topic-item-comp {
    display: flex;
    box-sizing: border-box;
  }
  .contanier {
    width: 1200px;
    margin: 0 auto;
    overflow: hidden;
    flex-direction: row;
    padding-top: 30px;
  }
  .edu-filter-box {
    width: 100%;
  }
  .edu-filter-box .category2-box {
    width: 100%;
    height: auto;
    background: #fff;
    padding: 18px 0 8px;
    box-sizing: border-box;
  }
  .edu-filter-box .category2-box .box .first-item {
    width: 42px;
    height: 14px;
    margin: 10px 42px 0 0;
    font-size: 14px;
    font-weight: 400;
    color: #333;
    line-height: 40px;
  }
  .content .contanier .left-contanier {
    width: 769px;
    min-height: 500px;
    display: flex;
    flex-direction: column;
    margin-right: 30px;
  }
  .topic-item-comp:last-child {
    margin-bottom: 10px;
  }
  .topic-item-comp {
    width: 100%;
    height: 140px;
    float: left;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    padding: 20px 30px;
  }
  .contanier, .topic-item-comp {
    display: flex;
    box-sizing: border-box;
  }
  .topic-item-comp .topic-thumb {
    width: 133px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    margin-right: 20px;
  }
  .topic-item-comp .topic-body {
    flex: 1;
    box-sizing: border-box;
    padding-top: 15px;
  }
  .topic-item-comp .topic-thumb img {
    width: 133px;
    height: 100px;
    border-radius: 8px;
    transition: all .4s;
  }
  .topic-item-comp .topic-body {
    flex: 1;
    box-sizing: border-box;
    padding-top: 15px;
  }
  .topic-item-comp .topic-body .topic-title {
    width: 556px;
    height: auto;
    float: left;
    margin-bottom: 28px;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    line-height: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topic-item-comp .topic-body .topic-info {
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
  }
  .topic-item-comp .topic-body .topic-info .category {
    padding: 5px 8px;
    background: rgba(255,80,104,.1);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 400;
    color: #ff5068;
    line-height: 14px;
    margin-right: 30px;
  }




  .paging {
    padding: 50px 0 20px;
    text-align: center;
  }
  .box {
    width: 1200px;
    height: auto;
    margin: 0 auto;
    display: flex;
    flex-direction: row;
  }
  .edu-filter-box .category2-box .box .item-box {
    width: 1068px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    flex-direction: row;
  }
  .edu-filter-box .category2-box .box .item-box .item.active {
    background-color: rgba(160,175,187,.15);
    border-radius: 4px;
    color: #3ca7fa;
  }
  .edu-filter-box .category2-box .box .item-box .item {
    width: auto;
    height: 34px;
    padding: 10px 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 30px;
    font-size: 14px;
    font-weight: 400;
    color: #333;
    line-height: 14px;
    cursor: pointer;
    margin-bottom: 10px;
  }

</style>
